package me.sunpeng.design.factory.factorymethod.pizzastore.order;

import me.sunpeng.design.factory.factorymethod.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 定义一个抽象方法，createPizza，让各个工厂子类自己实现
 *
 * @author sp
 */
public abstract class OrderPizza {

    //定义抽象方法，创建实例，各个工厂子类自己实现
    abstract Pizza createPizza(String orderType);

    //构造器
    public OrderPizza() {
        System.out.println(this.getClass().getName() + "调用父类构造器方法");
        System.out.println(this.getClass().getTypeName() + "调用父类构造器方法");
        System.out.println(this.getClass().getCanonicalName() + "调用父类构造器方法");
        System.out.println(this.getClass().getSimpleName() + "调用父类构造器方法");

        Pizza pizza;
        String orderPizza;
        do {
            orderPizza = getType();
            pizza = createPizza(orderPizza);
            //输出pizaa制作过程
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        } while (true);
    }

    private String getType() {
        try  {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza 种类");
            return strin.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }

}
